package com.xhs.service.impl;

import com.alibaba.fastjson2.JSONObject;
import com.xhs.config.ApiProperties;
import com.xhs.dto.request.SendHttpParam;
import com.xhs.message.ReturnResult;
import com.xhs.service.ForestHttp;
import com.xhs.service.TestService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;

/**
 * @desc:
 * @projectName: http-forest-api
 * @author: xhs
 * @date: 2024-06-10 12:26
 * @version: JDK 1.8
 */
@Slf4j
@Service
public class TestServiceImpl implements TestService {

    @Resource
    private ApiProperties apiProperties;
    @Resource
    private ForestHttp forestHttp;

    /**
     * 发送Get请求 无参
     *
     * @return JSONObject
     */
    @Override
    public ReturnResult<Object> sendGet() {
        JSONObject jsonObject = forestHttp.sendGet(apiProperties.getTest().getSendGetUrl());
        log.info("<--------发送Get请求 无参 jsonObject:{}-------->", jsonObject);
        return ReturnResult.success(jsonObject);
    }

    /**
     * 发送Get请求 有参
     *
     * @param param 入参
     * @return JSONObject
     */
    @Override
    public ReturnResult<Object> sendGetParam(SendHttpParam param) {
        JSONObject jsonObject = forestHttp.sendGetParam(apiProperties.getTest().getSendGetParamUrl(), param);
        log.info("<--------发送Get请求 有参 jsonObject:{}-------->", jsonObject);
        return ReturnResult.success(jsonObject);
    }


    /**
     * 发送Post请求 无参
     *
     * @return JSONObject
     */
    @Override
    public ReturnResult<Object> sendPost() {
        JSONObject jsonObject = forestHttp.sendPost(apiProperties.getTest().getSendPostUrl());
        log.info("<--------发送Post请求 无参 jsonObject:{}-------->", jsonObject);
        return ReturnResult.success(jsonObject);
    }

    /**
     * 发送Post请求 有参 json格式
     *
     * @param param 入参
     * @return JSONObject
     */
    @Override
    public ReturnResult<Object> sendPostParam(SendHttpParam param) {
        JSONObject jsonObject = forestHttp.sendPostJsonParam(apiProperties.getTest().getSendPostJsonParamUrl(), param);
        log.info("<--------发送Post请求 有参 json格式 jsonObject:{}-------->", jsonObject);
        return ReturnResult.success(jsonObject);
    }
}
